home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Context.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  1.7 KB  |  69 lines

  1. package symantec.itools.lang;
  2.  
  3. import java.applet.Applet;
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6.  
  7. public class Context {
  8.    private static Applet applet;
  9.    private static URL documentBase;
  10.    private static boolean initialized;
  11.  
  12.    public static boolean isApplet() {
  13.       return applet != null;
  14.    }
  15.  
  16.    public static boolean isApplication() {
  17.       return applet == null;
  18.    }
  19.  
  20.    public static void setApplet(Applet var0) {
  21.       applet = var0;
  22.       initialized = true;
  23.    }
  24.  
  25.    public static Applet getApplet() {
  26.       return applet;
  27.    }
  28.  
  29.    public static void setDocumentBase(URL var0) {
  30.       documentBase = var0;
  31.       initialized = true;
  32.    }
  33.  
  34.    private static void initializeApp() {
  35.       StringBuffer var0 = new StringBuffer(System.getProperty("user.dir"));
  36.       int var1 = var0.length();
  37.  
  38.       try {
  39.          char var2 = System.getProperty("file.separator").charAt(0);
  40.          if (var2 != '/') {
  41.             for(int var3 = 0; var3 < var1; ++var3) {
  42.                if (var2 == var0.charAt(var3)) {
  43.                   var0.setCharAt(var3, '/');
  44.                }
  45.             }
  46.          }
  47.       } catch (StringIndexOutOfBoundsException var5) {
  48.       }
  49.  
  50.       try {
  51.          documentBase = new URL("file://" + var0 + "/");
  52.       } catch (MalformedURLException var4) {
  53.       }
  54.    }
  55.  
  56.    public static URL getDocumentBase() {
  57.       if (!initialized) {
  58.          initializeApp();
  59.          initialized = true;
  60.       }
  61.  
  62.       if (documentBase != null) {
  63.          return documentBase;
  64.       } else {
  65.          return applet != null ? applet.getDocumentBase() : null;
  66.       }
  67.    }
  68. }
  69.